package org.tuoren.official.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tuoren.common.core.domain.R;
import org.tuoren.common.core.validate.AddGroup;
import org.tuoren.common.core.validate.EditGroup;
import org.tuoren.common.excel.utils.ExcelUtil;
import org.tuoren.common.idempotent.annotation.RepeatSubmit;
import org.tuoren.common.log.annotation.Log;
import org.tuoren.common.log.enums.BusinessType;
import org.tuoren.common.mybatis.core.page.PageQuery;
import org.tuoren.common.mybatis.core.page.TableDataInfo;
import org.tuoren.common.web.core.BaseController;
import org.tuoren.official.domain.bo.TBusinessSupportBo;
import org.tuoren.official.domain.vo.TBusinessSupportVo;
import org.tuoren.official.service.ITBusinessSupportService;

import java.util.List;

/**
 * 商务配套设施
 *
 * @author Lion Li
 * @since 2024-11-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/official/businessSupport")
public class TBusinessSupportController extends BaseController {

    private final ITBusinessSupportService tBusinessSupportService;

    /**
     * 查询商务配套设施列表
     */
    @SaCheckPermission("official:businessSupport:list")
    @GetMapping("/list")
    public TableDataInfo<TBusinessSupportVo> list(TBusinessSupportBo bo, PageQuery pageQuery) {
        return tBusinessSupportService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出商务配套设施列表
     */
    @SaCheckPermission("official:businessSupport:export")
    @Log(title = "商务配套设施", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TBusinessSupportBo bo, HttpServletResponse response) {
        List<TBusinessSupportVo> list = tBusinessSupportService.queryList(bo);
        ExcelUtil.exportExcel(list, "商务配套设施", TBusinessSupportVo.class, response);
    }

    /**
     * 获取商务配套设施详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("official:businessSupport:query")
    @GetMapping("/{id}")
    public R<TBusinessSupportVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(tBusinessSupportService.queryById(id));
    }

    /**
     * 新增商务配套设施
     */
    @SaCheckPermission("official:businessSupport:add")
    @Log(title = "商务配套设施", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TBusinessSupportBo bo) {
        return toAjax(tBusinessSupportService.insertByBo(bo));
    }

    /**
     * 修改商务配套设施
     */
    @SaCheckPermission("official:businessSupport:edit")
    @Log(title = "商务配套设施", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/edit")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TBusinessSupportBo bo) {
        return toAjax(tBusinessSupportService.updateByBo(bo));
    }

    /**
     * 删除商务配套设施
     *
     * @param ids 主键串
     */
    @SaCheckPermission("official:businessSupport:remove")
    @Log(title = "商务配套设施", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(tBusinessSupportService.deleteWithValidByIds(List.of(ids), true));
    }

    /**
     * 官网-服务中心商务配套设施列表
     * @return 商务配套设施列表
     */
    @SaIgnore
    @GetMapping("/getlist")
    public TableDataInfo<TBusinessSupportVo> getList(String type){
        return TableDataInfo.build(tBusinessSupportService.getList(type));
    }
}
